package com.example.apiproject.service.impl;

import com.alibaba.fastjson.JSON;
import com.example.apiproject.entity.Information;
import com.example.apiproject.dao.InformationDao;
import com.example.apiproject.service.InformationService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Information)表服务实现类
 *
 * @author makejava
 * @since 2024-04-03 23:03:28
 */
@Service("informationService")
public class InformationServiceImpl implements InformationService {
    @Resource
    private InformationDao informationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Information queryById(Integer id) {
        return this.informationDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param information 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Information> queryByPage(Information information, PageRequest pageRequest) {
        long total = this.informationDao.count(information);
        return new PageImpl<>(this.informationDao.queryAllByLimit(information, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param information 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(Information information) {

        int num=this.informationDao.insert(information);
        return num;
    }

    /**
     * 修改数据
     *
     * @param information 实例对象
     * @return 实例对象
     */
    @Override
    public Information update(Information information) {
        this.informationDao.update(information);
        return this.queryById(information.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.informationDao.deleteById(id) > 0;
    }
}
